/**
 * 
 */
package stc.skymobi.fsm.test;

import java.util.Random;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import xiaojian.toolkit.fsm.DefaultFSM;


/**
 * @author hp
 *
 */


public class FSMDemo {

	private static Id genEvent() {
		Id ret = null;
		Random r = new Random();
		
		int i1 = r.nextInt();
		int i2 = r.nextInt();
		
		if ( i1 % 2 == 1 ) {
			ret = new CoinEvent();
		}
		else {
			ret = new PassEvent();
		}
		
		ret.setId(Math.abs(i2) % 4);
		
		return ret;
	}
	
    public static void main(String[] args) throws InterruptedException {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
            	"com/skymobi/fsm/test/fsmDemo.xml");

    	DefaultFSM fsm = (DefaultFSM)ctx.getBean("fsm");

    	while (true) {
    		fsm.acceptEvent(genEvent());
    		
    		Thread.sleep(10);
    	}
    }
}
